/*****************************/
/* This do file calculate pivot positions and government positions for all member states*/
/* It uses the Marks and Steenbergen data */
/* Load Marks and Steenbergen expert position data*/
/* Input file: marks_steenbergen99.dta */
/* Output file: MSexpert99.dta */
/* JBS 02/02/05, revised JBS July 2005 */
/*****************************/

* Here I use data from Marks and Steenbergen avaliable on Gary Marks's website. 

use marks_steenbergen99.dta, clear

keep if (year==96| year==99)      /*only keep years 1996 and 1999 approximately the time of IGC negs*/

sort country party year 

/* Here I add in 1997 party seat shares from Hug and Koenig data */ 

gen LHseats=.        /*this variable will contain lower house seat shares*/
gen UPseats=.        /*this variable will contain upper house seat shares*/

replace LHseats=5 if party=="AGALEV" & country==1    /*number of seats for each party in Belgian parliament for both houses*/
replace UPseats=1 if party=="AGALEV" & country==1
replace LHseats=29 if party=="CVP" & country==1
replace UPseats=7 if party=="CVP" & country==1
replace LHseats=6 if party=="ECOLO" & country==1
replace UPseats=2 if party=="ECOLO" & country==1
replace LHseats=21 if party=="PS" & country==1
replace UPseats=6 if party=="PS" & country==1
replace LHseats=20 if party=="SP" & country==1
replace UPseats=6 if party=="SP" & country==1
replace LHseats=12 if party=="PSC" & country==1
replace UPseats=3 if party=="PSC" & country==1
replace LHseats=18 if party=="PRL" & country==1
replace UPseats=5 if party=="PRL" & country==1
replace LHseats=21 if party=="PVV/VLD" & country==1
replace UPseats=6 if party=="PVV/VLD" & country==1
replace LHseats=5 if party=="VU" & country==1
replace UPseats=2 if party=="VU" & country==1
replace LHseats=11 if party=="VB" & country==1
replace UPseats=3 if party=="VB" & country==1

replace LHseats=63 if party=="SD" & country==2   /*Danish Parliament*/
replace LHseats=7 if party=="RV" & country==2
replace LHseats=16 if party=="KF" & country==2
replace LHseats=8 if party=="CD" & country==2
replace LHseats=13 if party=="SF" & country==2
replace LHseats=4 if party=="KRF" & country==2
replace LHseats=42 if party=="V" & country==2
replace LHseats=4 if party=="FP" & country==2
replace LHseats=5 if party=="EL" & country==2

replace LHseats=295 if party=="CDU" & country==3   /*German Parliament */
replace UPseats=21 if party=="CDU" & country==3
replace LHseats=47 if party=="FDP" & country==3
replace UPseats=3 if party=="FDP" & country==3
replace LHseats=251 if party=="SPD" & country==3
replace UPseats=41 if party=="SPD" & country==3
replace LHseats=48 if party=="GRUN" & country==3
replace UPseats=4 if party=="GRUN" & country==3
replace LHseats=30 if party=="PDS" & country==3
replace UPseats=0 if party=="PDS" & country==3

replace LHseats=162 if party=="PASOK" & country==4
replace LHseats=108 if party=="ND" & country==4
replace LHseats=11 if party=="KKE" & country==4
replace LHseats=10 if party=="SAP" & country==4   
replace LHseats=10 if party=="SYN" & country==4
replace LHseats=9 if party=="DIKKI" & country==4

replace LHseats=141 if party=="PSOE" & country==5
replace UPseats=81 if party=="PSOE" & country==5
replace LHseats=156 if party=="PP" & country==5
replace UPseats=111 if party=="PP" & country==5
replace LHseats=21 if party=="IU" & country==5
replace UPseats=0 if party=="IU" & country==5
replace LHseats=16 if party=="CiU" & country==5
replace UPseats=8 if party=="CiU" & country==5
replace LHseats=5 if party=="PNV" & country==5
replace UPseats=4 if party=="PNV" & country==5
replace LHseats=4 if party=="CC" & country==5
replace UPseats=2 if party=="CC" & country==5
replace LHseats=1 if party=="ERC" & country==5
replace UPseats=0 if party=="ERC" & country==5
replace LHseats=1 if party=="UV" & country==5
replace UPseats=0 if party=="UV" & country==5
replace LHseats=2 if party=="BNG" & country==5
replace UPseats=0 if party=="BNG" & country==5
replace LHseats=1 if party=="EA" & country==5
replace UPseats=0 if party=="EA" & country==5
replace LHseats=2 if party=="HB" & country==5
replace UPseats=0 if party=="HB" & country==5

replace LHseats=38 if party=="PCF" & country==6
replace UPseats=14 if party=="PCF" & country==6
replace LHseats=241 if party=="PS" & country==6
replace UPseats=73 if party=="PS" & country==6
replace LHseats=21 if party=="MRG" & country==6
replace UPseats=11 if party=="MRG" & country==6
replace LHseats=7 if party=="VERTS" & country==6
replace UPseats=0 if party=="VERTS" & country==6
replace LHseats=108 if party=="UDF" & country==6
replace UPseats=106 if party=="UDF" & country==6
replace LHseats=134 if party=="RPR" & country==6
replace UPseats=86 if party=="RPR" & country==6
replace LHseats=1 if party=="FN" & country==6
replace UPseats=0 if party=="FN" & country==6

replace LHseats=77 if party=="FF" & country==7
replace UPseats=29 if party=="FF" & country==7
replace LHseats=54 if party=="FG" & country==7
replace UPseats=17 if party=="FG" & country==7
replace LHseats=17 if party=="LP" & country==7
replace UPseats=3 if party=="LP" & country==7
replace LHseats=2 if party=="GREENS" & country==7
replace UPseats=0 if party=="GREENS" & country==7
replace LHseats=4 if party=="PD" & country==7
replace UPseats=4 if party=="PD" & country==7
replace LHseats=1 if party=="SF" & country==7
replace UPseats=0 if party=="SF" & country==7
replace LHseats=4 if party=="DLP" & country==7
replace UPseats=0 if party=="DLP" & country==7

/*In Italy, government is pivotal- gov pos is pivot pos- gov controls a majority in both chambers*/
/* Ulivo coalition holds the pivot pos- the code below generates the gov seat share for parties in gov*/
/* the lower house seat shares are actually the %votes the party won on the PR ballot*/
/* I use this as a proxy for how many seats the parties bring to the gov*/

replace LHseats=21 if party=="PDS" & country==8
replace LHseats=2.333 if party=="PPI" & country==8
replace LHseats=2.333 if party=="SVP" & country==8
replace LHseats=2.333 if party=="PRI" & country==8
replace LHseats=4 if party=="RI" & country==8
replace LHseats=2.5 if party=="FdV" & country==8
replace LHseats=8.6 if party=="RC" & country==8

replace LHseats=45 if party=="PvdA" & country==10
replace UPseats=14 if party=="PvdA" & country==10
replace LHseats=29 if party=="CDA" & country==10
replace UPseats=19 if party=="CDA" & country==10
replace LHseats=38 if party=="VVD" & country==10
replace UPseats=23 if party=="VVD" & country==10
replace LHseats=14 if party=="D'66" & country==10
replace UPseats=7 if party=="D'66" & country==10
replace LHseats=11 if party=="GL" & country==10
replace UPseats=4 if party=="GL" & country==10
replace LHseats=3 if party=="RPF" & country==10
replace UPseats=1 if party=="RPF" & country==10
replace LHseats=2 if party=="GPV" & country==10
replace UPseats=1 if party=="GPV" & country==10
replace LHseats=3 if party=="SGP" & country==10
replace UPseats=2 if party=="SGP" & country==10
replace LHseats=5 if party=="SP" & country==10
replace UPseats=1 if party=="SP" & country==10

replace LHseats=165 if party=="TORY" & country==11
replace LHseats=419 if party=="LAB" & country==11
replace LHseats=46 if party=="LDP" & country==11
replace LHseats=6 if party=="SNP" & country==11
replace LHseats=4 if party=="CYMRU" & country==11
replace LHseats=3 if party=="SDLP" & country==11

replace LHseats=15 if party=="PCP" & country==12  
replace LHseats=15 if party=="CDU" & country==12  /*in a coalition with PCP*/
replace LHseats=15 if party=="CDS-PP" & country==12
replace LHseats=112 if party=="PSP" & country==12
replace LHseats=88 if party=="PPD/PSD" & country==12

replace LHseats=71 if party=="SPO" & country==13
replace UPseats=24 if party=="SPO" & country==13
replace LHseats=52 if party=="OVP" & country==13
replace UPseats=26 if party=="OVP" & country==13
replace LHseats=42 if party=="FPO" & country==13
replace UPseats=14 if party=="FPO" & country==13
replace LHseats=9 if party=="GA" & country==13
replace UPseats=0 if party=="GA" & country==13
replace LHseats=9 if party=="LF" & country==13
replace UPseats=0 if party=="LF" & country==13

replace LHseats=44 if party=="KESK" & country==14
replace LHseats=63 if party=="SSDP" & country==14
replace LHseats=39 if party=="KOK" & country==14
replace LHseats=22 if party=="VL" & country==14
replace LHseats=12 if party=="RKP/SFP" & country==14
replace LHseats=9 if party=="VIHR" & country==14
replace LHseats=7 if party=="SKL" & country==14
replace LHseats=1 if party=="SMP" & country==14

replace LHseats=80 if party=="MSP" & country==16
replace LHseats=26 if party=="FPL" & country==16
replace LHseats=27 if party=="CP" & country==16
replace LHseats=15 if party=="KdS" & country==16
replace LHseats=161 if party=="SAP" & country==16
replace LHseats=22 if party=="V" & country==16
replace LHseats=18 if party=="MP" & country==16

/* Here I create a dummy variable which is 1 for those parties in government at the time of the Amsterdam IGC*/

gen government=1 if ((party=="PS"|party=="PSC"|party=="CVP"|party=="SP") &country==1)
replace government=1 if ((party=="RV"|party=="SD") & country==2)
replace government=1 if ((party=="CDU"|party=="CSU"|party=="FDP") & country==3)
replace government=1 if (party=="PASOK" & country==4)
replace government=1 if (party=="PP" & country==5)
replace government=1 if (party=="RPR" & country==6)
replace government=1 if ((party=="PD"|party=="FF") & country==7)
replace government=1 if ((party=="PDS"|party=="PPI"|party=="RI"|party=="FdV"|party=="RC"|party=="SVP"|party=="PRI") & country==8)
replace government=1 if ((party=="PvdA"|party=="D'66"|party=="VVD") & country==10)
replace government=1 if (party=="LAB" & country==11)
replace government=1 if (party=="PSP" & country==12)
replace government=1 if ((party=="OVP"|party=="SPO") & country==13)
replace government=1 if ((party=="KOK"|party=="SSDP"|party=="VL"|party=="VIHR") & country==14)
replace government=1 if (party=="SAP" & country==16)

save temp1.dta, replace

/* create dataset of only 1996 responses*/
drop if year==99
rename position position96
save mstemp1996.dta,replace

/* create dataset of only 1999 responses*/
use temp1.dta, clear
drop if year==96
rename position position99
sort party_id country
save mstemp1999, replace

/* calculate lower house pivots in 1996 dataset*/
use mstemp1996.dta
sort country position96
drop if LHseats==.
by country: egen totalseatsLH= sum(LHseats)
gen LHseatshare=LHseats/totalseatsLH

/* I calculate the pivots manually. I sort the parties in the lower house according to their positions, */
/* then I add their seat shares until there are sufficient votes reach the ratification threshold. */
/* Below I create a dummy variable which is one the lower house pivot in each country. */

gen LHpivot=1 if (party=="PSC" | party=="RV" | party=="SPD" | party=="PASOK" | party=="PP" | (party=="PS"& country==6) | party=="FF" |party=="LN" |party=="PvdA" |party=="LAB"| party=="PPD/PSD" |party=="OVP"|party=="KESK"|(party=="SAP"& country==16))

sort LHpivot position96
list country party LHseatshare LHpivot position96 dissent

save mstemp1996LH.dta, replace

/*merge 99 and 96 datasets to examine correlation between party positions over time*/

use mstemp1996, clear
sort party_id country
merge party_id country using mstemp1999, keep(position99)
corr position96 position99

save mstemp1996, replace

use mstemp1999, clear
sort country position 
drop if LHseats==.
by country: egen totalseatsLH= sum(LHseats)
gen LHseatshare=LHseats/totalseatsLH
save mstemp1999LH, replace

use mstemp1999, clear
sort country position
drop if UPseats==.
by country: egen totalseatsUP= sum(UPseats)
gen UPseatshare=UPseats/totalseatsUP
save mstemp1999UP, replace

/* I use these two temporary files- mstemp1999LH and mstemp1999UP to manually calculate the position of the pivots by issue area for each member state */
/* By issue area I sort the party position. I then count the number of seats until I reach enough seats to pass the ratification threshold.*/
/* The final party needed to reach the ratification threshold is the pivotal party. */
/* Each pivot in each chamber by issue area is listed in the excel worksheet MSpivots. This worksheet also averages the pivots across issue areas. */
 
/* create government positions*/
use mstemp1999LH
gen LHgovseats=LHseats if government==1
replace LHgovseats=0 if government~=1
bys country: egen totalgovseats= sum(LHgovseats)
gen govseatshare= LHseats/totalgovseats
bys country: egen numpartiesgov=sum(government)

bys country: gen govposwEP1=ep*govseatshare if government==1
bys country: gen govposEP1=ep if government==1
bys country: egen govposaveEP= mean(govposEP1)
by country: egen govposwaveEP= sum(govposwEP1)
by country: egen govposminEP=min(ep) if government==1
by country: egen govposmaxEP=max(ep) if government==1

bys country: gen govposwfiscal1=fiscal*govseatshare if government==1
bys country: gen govposfiscal1=fiscal if government==1
bys country: egen govposavefiscal= mean(govposfiscal1)
by country: egen govposwavefiscal= sum(govposwfiscal1)
by country: egen govposminfiscal=min(fiscal) if government==1
by country: egen govposmaxfiscal=max(fiscal) if government==1

bys country: gen govposwemploy1=employ*govseatshare if government==1
by country: egen govposwaveemploy= sum(govposwemploy1)
bys country: gen govposemploy1=employ if government==1
bys country: egen govposaveemploy= mean(govposemploy1)
by country: egen govposminemploy=min(employ) if government==1
by country: egen govposmaxemploy=max(employ) if government==1

bys country: gen govposwcohesion1=cohesion*govseatshare if government==1
by country: egen govposwavecohesion= sum(govposwcohesion1)
bys country: gen govposcohesion1=cohesion if government==1
bys country: egen govposavecohesion= mean(govposcohesion1)
by country: egen govposmincohesion=min(cohesion) if government==1
by country: egen govposmaxcohesion=max(cohesion) if government==1

bys country: gen govposwenviron1=environ*govseatshare if government==1
by country: egen govposwaveenviron= sum(govposwenviron1)
bys country: gen govposenviron1=environ if government==1
bys country: egen govposaveenviron= mean(govposenviron1)
by country: egen govposminenviron=min(environ) if government==1
by country: egen govposmaxenviron=max(environ) if government==1

bys country: gen govposwasylum1=asylum*govseatshare if government==1
by country: egen govposwaveasylum= sum(govposwasylum1)
bys country: gen govposasylum1=asylum if government==1
bys country: egen govposaveasylum= mean(govposasylum1)
by country: egen govposminasylum=min(asylum) if government==1
by country: egen govposmaxasylum=max(asylum) if government==1

bys country: gen govposwforeign1=foreign*govseatshare if government==1
by country: egen govposwaveforeign= sum(govposwforeign1)
bys country: gen govposforeign1=foreign if government==1
bys country: egen govposaveforeign= mean(govposforeign1)
by country: egen govposminforeign=min(foreign) if government==1
by country: egen govposmaxforeign=max(foreign) if government==1

bys country: gen wavegovpos= (govposwaveEP+govposwavefiscal+govposwaveemploy+govposwavecohesion+govposwaveenviron+govposwaveasylum+govposwaveforeign)/7
bys country: gen avegovpos= (govposaveEP+govposavefiscal+govposaveemploy+govposavecohesion+govposaveenviron+govposaveasylum+govposaveforeign)/7

sort avegovpos
list country avegovpos
list country wavegovpos



